package week4.onClass.exer03;

import java.util.Scanner;

public class Main {

    private static int totalCount = 0;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }
        partition(arr, 0, n - 1);
        System.out.println(totalCount);
    }

    private static void partition(int[] arr, int left, int right) {
        if (left >= right) {
            return;
        }
        int mid = (left + right) / 2;
        partition(arr, left, mid);
        partition(arr, mid + 1, right);
        int left1 = left;
        int left2 = mid + 1;
        int right1 = mid;
        int right2 = right;
        int[] tmp = new int[right - left + 1];
        int index = 0;
        while (left1 <= right1 && left2 <= right2) {
            if (arr[left1] <= arr[left2]) {
                tmp[index++] = arr[left2];
                left2++;
            } else {
                totalCount += (right2 - left2 + 1);
                tmp[index++] = arr[left1];
                left1++;
            }
        }
        while (left1 <= right1) {
            tmp[index++] = arr[left1];
            left1++;
        }
        while (left2 <= right2) {
            tmp[index++] = arr[left2];
            left2++;
        }
        for (int i = 0; i < index; i++) {
            arr[left + i] = tmp[i];
        }
    }
}
